package com.yztc.love_travel.ui.recommondtripnotes.presenter;

import android.util.Log;

import com.yztc.love_travel.bean.homepage.RecommendTripNotesBean;
import com.yztc.love_travel.ui.recommondtripnotes.model.IRecommendTripNotesModel;
import com.yztc.love_travel.ui.recommondtripnotes.model.RecommendTripNotesModelImpl;
import com.yztc.love_travel.ui.recommondtripnotes.view.IRecommendTripNotesView;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by 周旭 on 2016/11/29.
 */

public class RecommendTripNotesPresenterImpl implements IRecommendTripNotesPresenter{

    private IRecommendTripNotesModel mRecommendTripNotesModel;
    private IRecommendTripNotesView mRecommendTripNotesView;

    public RecommendTripNotesPresenterImpl(IRecommendTripNotesView mRecommendTripNotesView) {
       mRecommendTripNotesModel = new RecommendTripNotesModelImpl();
        this.mRecommendTripNotesView = mRecommendTripNotesView;
    }

    @Override
    public void getRecommendTripNotes(String baseUrl, Map<String, Object> params) {
        mRecommendTripNotesModel.getRecommendTripNotesBean(baseUrl,params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<RecommendTripNotesBean>() {
                    @Override
                    public void onCompleted() {
                        Log.i("tag","---------->onCompleted");
                    }

                    @Override
                    public void onError(Throwable e) {
                        mRecommendTripNotesView.loadError();
                    }

                    @Override
                    public void onNext(RecommendTripNotesBean recommendTripNotesBean) {
                        mRecommendTripNotesView.showData(recommendTripNotesBean);
                    }
                });
    }
}
